<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :model="queryParams" size="mini" inline>
      <el-form-item prop="progressChkType">
        <el-select v-model="queryParams.progressChkType" placeholder="检查类型" style="width: 120px;" clearable>
          <el-option v-for="dict in dict.type.cq_progress_chk_type" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item prop="deptId1">
        <treeselect
          v-model="queryParams.deptId1"
          class="tree-select-custom"
          :options="deptOptions"
          no-results-text="暂无数据匹配"
          no-options-text="暂无数据"
          :normalizer="normalizerDept"
          @select="getProjectList"
          placeholder="请选择所属部门"
        />
      </el-form-item>
      <el-form-item prop="projectName">
        <el-input v-model.trim="queryParams.projectName" placeholder="请输入项目名称" clearable @keyup.enter.native="handleQuery" style="width: 160px" />
      </el-form-item>
      <el-form-item prop="rdcType" v-if="hasRandomType">
        <el-select v-model="queryParams.rdcType" placeholder="检查单位" clearable style="width: 100px">
          <el-option v-for="dict in dict.type.cq_random_type" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item prop="isLockout">
        <el-select v-model="queryParams.isLockout" placeholder="锁定状态" clearable style="width: 100px">
          <el-option v-for="dict in lockStatusList" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="检查开始日期"
          end-placeholder="检查结束日期"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        <el-button type="primary" icon="el-icon-plus" @click="handleAdd" v-hasPermi="[`cq:${CHECK_TYPE_CODE.JZGC}:add`]" v-show="processType === CHECK_TYPE_CODE.JZGC">新增</el-button>
        <el-button type="primary" icon="el-icon-plus" @click="handleAdd" v-hasPermi="[`cq:${CHECK_TYPE_CODE.TJGC}:add`]" v-show="processType === CHECK_TYPE_CODE.TJGC">新增</el-button>
        <el-button icon="el-icon-download" :loading="exportLoading" @click="handleExport" v-if="showBtns.isExport">导出</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" size="small" :data="constructionList" @selection-change="handleSelectionChange">
      <!--<el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="检查类型" align="center" min-width="80" key="progressChkType">
        <dict-tag slot-scope="{ row }" :options="dict.type.cq_progress_chk_type" :value="row.progressChkType" />
      </el-table-column>
      <el-table-column label="所属部门" prop="showDeptName" show-overflow-tooltip min-width="200" key="showDeptName" />
      <el-table-column label="项目" prop="projectName" :show-overflow-tooltip="true" width="150" key="projectName" />
      <el-table-column label="检查标段" prop="section" show-overflow-tooltip width="80" key="section" />
      <el-table-column label="项目(检查口径)" prop="inpectionCaliber" show-overflow-tooltip width="110" key="inpectionCaliber" />
      <el-table-column label="施工单位" prop="constructionName" show-overflow-tooltip min-width="200" key="constructionName" />
      <el-table-column label="检查单位" align="center" min-width="80" key="rdcType">
        <dict-tag slot-scope="{ row }" :options="dict.type.cq_random_type" :value="row.rdcType" />
      </el-table-column>

      <el-table-column v-for="(item, index) in scoreTypeList" :key="item.chkitemCode" :label="item.chkitemName" align="center" min-width="100">
        <template slot-scope="{ row }">
          <el-popover placement="top" trigger="hover" v-if="row.scores[index].children && row.scores[index].children.length > 0">
            <div class="material-tab">
              <div class="material-item item-special" v-for="sub in row.scores[index].children" :key="sub.chkitemCode" :class="sub.scoreResult">
                <div v-if="!sub.children || (sub.children && sub.children.length == 0)" class="item-cursor" @click="leakage(sub, row)">
                  <div>{{ sub.chkitemName }}</div>
                  <div>{{ sub.scoreInput || '/' }}</div>
                </div>
                <div v-else class="material-item-type">
                  <div>
                    <div>{{ sub.chkitemName }}</div>
                    <div>{{ sub.scoreInput || '/' }}</div>
                  </div>
                  <div class="type-line" />
                  <div class="gc-bs">
                    <div v-for="(type, tyindex) in sub.children" :key="'yt'+tyindex" class="label-value" @click="leakage(type, row)">
                      <span>{{ type.productType | productType }}</span>
                      <span> {{ type.scoreInput || '/' }} </span>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div slot="reference" class="material-item item-cursor" :class="row.scores[index].scoreResult">
              <div v-if="row.scores[index].scoreLevel">
                <span>{{ row.scores[index].scoreLevel }}</span>
                <span v-if="row.scores[index].scoreInput">({{ row.scores[index].scoreInput }})</span>
              </div>
              <span v-else>{{ row.scores[index].scoreInput || '/' }}</span>
            </div>
          </el-popover>
          <div v-else class="material-item item-cursor" :class="row.scores[index].scoreResult" @click="leakage(row.scores[index],row)">
            <div v-if="row.scores[index].scoreLevel">
              <span>{{ row.scores[index].scoreLevel }}</span>
              <span v-if="row.scores[index].scoreInput">({{ row.scores[index].scoreInput }})</span>
            </div>
            <span v-else>{{ row.scores[index].scoreInput || '/' }}</span>
          </div>
        </template>
      </el-table-column>

      <!--<el-table-column label="检查得分" min-width="360">-->
      <!--<template slot-scope="{ row }">-->
      <!--<ScoreDisplay :value="row" calculate="calculate" @clickScore="leakage($event,row)" :cfg="cfgInfo" />-->
      <!--</template>-->
      <!--</el-table-column>-->
      <el-table-column label="检查时间" align="center" prop="checkDate" width="100" />
      <el-table-column label="检查人员" align="center" show-overflow-tooltip min-width="100" prop="principalUserName" />
      <el-table-column label="锁定状态" align="center" width="70" fixed="right">
        <div slot-scope="{ row }">
          <div @click="toggleIsEnable(row)" style="display: inline-block; cursor: pointer" v-if="row.isEditEnable">
            <i class="el-icon-loading" v-if="!!row.isEnableLoading" />
            <el-switch class="g-switch-in" v-model="row.isLockout" :active-value="1" :inactive-value="0" active-text="锁定" inactive-text="未锁" :width="50" style="pointer-events: none" v-else />
          </div>
          <el-tag size="small" :type="row.isLockout ? 'primary' : 'info'" v-else>{{ row.isLockout ? '锁定' : '未锁' }}</el-tag>
        </div>
      </el-table-column>
      <el-table-column label="操作" width="220" fixed="right" class-name="small-padding">
        <template slot-scope="{ row }">
          <div v-if="row.showBtns">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(row)" v-if="row.showBtns.edit && !row.isLockout">修改</el-button>
            <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(row)" v-if="row.showBtns.remove && !row.isLockout">删除</el-button>
            <el-button size="mini" type="text" icon="el-icon-plus" @click="handleRecheck(row)" v-if="row.showBtns.recheck && row.isLockout && row.isRecheck">{{ row.chkStep === chkStep.NEEDRECHK ? '复查' : '重新检查' }}</el-button>
            <el-button size="mini" type="text" icon="el-icon-tickets" @click="handleDetail(row)" v-if="row.showBtns.itemInfo">详情</el-button>
            <el-button icon="el-icon-download" type="text" :loading="row.exportLoading" @click="handleTaskExport(row)" v-if="showBtns.isExport && row.isLockout">导出</el-button>
            <el-button size="mini" type="text" icon="el-icon-view" :disabled="previewDisabled(row)" @click="handleReportPreview(row)" v-if="row.showBtns.preview && row.rdcType === 'DEPT1'">预览</el-button>
            <el-button size="mini" type="text" icon="el-icon-delete" :loading="row.forceRemoveLoading" @click="handleForceRemove(row)" v-if="row.showBtns.forceRemove && !row.isLockout">强制删除</el-button>
          </div>
          <!--
          <el-button size="mini" type="text" icon="el-icon-tickets" @click="handleDetail(row)" v-if="row.showBtns.itemInfo">详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleReportPreview(row)" :disabled="previewDisabled(row)" v-if="row.showBtns.preview && row.rdcType === 'DEPT1'">预览</el-button>
          <el-dropdown>
            <el-button size="mini" type="text" icon="el-icon-more" style="margin-left: 10px">更多</el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item icon="el-icon-edit" @click.native="handleUpdate(row)" v-if="row.showBtns.edit && !row.isLockout">修改</el-dropdown-item>
              <el-dropdown-item icon="el-icon-delete" @click.native="handleDelete(row)" v-if="row.showBtns.remove && !row.isLockout" style="color: #f56c6c">删除</el-dropdown-item>
              <el-dropdown-item icon="el-icon-edit" @click.native="$refs.OutsideQuesList.open(row)">测区外问题</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!--新增与修改土建过程-->
    <add-update ref="addUpdateRef" :process-type="processType" @close="getList" />
    <!--防渗漏-->
    <antiseep ref="antiseepRef" :process-type="processType" @submitSuccess="submitSuccess" />
    <!-- 详情 -->
    <construction-detail ref="constructionDetailRef" :cfg="cfgInfo" />
    <jz-report-preview v-if="processType === CHECK_TYPE_CODE.JZGC" ref="handcoverReportPreviewRef" />
    <tj-report-preview v-if="processType === CHECK_TYPE_CODE.TJGC" ref="civilReportPreviewRef" />
    <OutsideQuesList ref="OutsideQuesList" />
  </div>
</template>

<script>
import auth from '@/plugins/auth'
import { inspectTypeListWithKey, lockStatusList, chkStep, CQ_EVAL_DATA_TYPE as DATA_TYPE, cqProductType } from '@/utils/baseData'
import { CHECK_TYPE_CODE } from './baseData'
import {
  getProcessWordRecord
} from '@/api/projectInspection/courseCheck'
import { cqEvalPrjchkRemove, cqEvalPrjchkForceRemove } from '@/api/checkScore/courseCheck'
import { pageScorePrjchk, listChkitem, enableTaskPrjchk, disableTaskPrjchk, exportReportPrjchk } from '@/api/checkScore/cqEval'

import { treeselect } from '@/api/system/dept'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import Antiseep from './components/antiseep'
import ConstructionDetail from './components/constructionDetail'
import addUpdate from './components/addUpdate'
import TjReportPreview from './components/TjReportPreview'
import JzReportPreview from './components/JzReportPreview'
import OutsideQuesList from './components/OutsideQuesList'
// import ScoreDisplay from './components/ScoreDisplay'

// 移除 '管理动作'; '空鼓开裂'字段有差异，改为 zlKg
const inspectTypeList = JSON.parse(JSON.stringify(inspectTypeListWithKey))
inspectTypeList.map(item =>
  item.scoreTypeList.map((i, index) => {
    if (i.key === 'gldz') item.scoreTypeList.splice(index, 1)
    if (i.children) i.children.map(j => j.key === 'zlKgkl' && (j.key = 'zlKg'))
  })
)

export default {
  name: 'ConstructionCourse',
  components: {
    Treeselect,
    Antiseep,
    ConstructionDetail,
    addUpdate,
    TjReportPreview,
    JzReportPreview,
    OutsideQuesList
    // ScoreDisplay
  },
  dicts: ['cq_random_type', 'cq_process_type', 'cq_progress_chk_type'],
  filters: {
    scoreClass(val, scoreType) {
      if (!val) return ''
      if (scoreType === 'fsl') {
        if (val === 'A') return 'blue'
        if (val === 'B' || val === 'C') return 'red'
        return ''
      }
      if (val === 'A' || val >= 90) return 'green'
      if (val === 'B' || (val < 90 && val >= 80)) return 'blue'
      if (val === 'C' || val < 80) return 'red'
      return ''
    },
    scoreName(item = {}, key, isLevel1) {
      // 一级大类才显示等级
      const level = isLevel1 ? item[`${key}Level`] || '' : ''
      const score = item[`${key}Score`] || ''
      const val = level ? `${level}${score ? `(${score})` : ''}` : score
      return val || '/'
    },
    productType(val) {
      let str = val
      for (let i = 0; i < cqProductType.length; i++) {
        if (cqProductType[i].value === val) {
          str = cqProductType[i].label
        }
      }
      return str
    }
  },
  data() {
    return {
      CHECK_TYPE_CODE: CHECK_TYPE_CODE,
      lockStatusList,
      antiseepShow: true,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 土建表格数据
      constructionList: [],
      // 日期范围
      dateRange: [],
      // 专业类别
      specialTypes: [],
      // 部门树选项
      deptOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        progressChkType: '',
        deptId1: undefined,
        projectName: undefined,
        rdcType: '',
        isLockout: '',
        startTime: '',
        endTime: '',
        versionCode: '',
        chkitemCode: ''
      },
      hasRandomType: false,
      exportLoading: false,
      processType: '', // 检查过程编码
      specialTypeName: '', // 专业类别名称
      chkStep: chkStep,
      cfgInfo: {},
      scoreTypeList: []
    }
  },
  computed: {
    showBtns() {
      // 操作按钮权限
      const { processType } = this
      const edit = auth.hasPermi(`cq:${processType}:edit`)
      const remove = auth.hasPermi(`cq:${processType}:remove`)
      const itemInfo = auth.hasPermi(`cq:${processType}:itemInfo`)
      const preview = auth.hasPermi(`cq:${processType}:preview`)
      // 有权解锁(启用)
      const enable = auth.hasPermi(`cq:${processType}:enable`)
      // 有权锁定(禁用)
      const disable = auth.hasPermi(`cq:${processType}:disable`)
      const isExport = auth.hasPermi(`cq:${processType}:export`)
      // 复查
      const recheck = auth.hasPermi(`cq:${processType}:recheck`)
      const forceRemove = auth.hasPermi(`cq:${processType}:forceRemove`)
      return { edit, remove, itemInfo, preview, enable, disable, isExport, recheck, forceRemove }
    }
  },
  created() {
    this.cfgInfo = { ...this.$route.query }
    this.specialTypeName = this.$route.query.chkitemName
    this.processType = this.$route.query.chkitemCode
    this.getSpecialList()
    this.getDeptTree()
  },
  methods: {
    // 判断 检查单位 权限
    getRandoTypePermission() {
      const hasDept1 = auth.hasPermi(`${this.processType}:DEPT1`) // 有集团 权限
      const hasDept2 = auth.hasPermi(`${this.processType}:DEPT2`) // 有集群 权限
      if (hasDept1 && hasDept2) {
        this.queryParams.rdcType = ''
        this.hasRandomType = true
      } else {
        this.hasRandomType = false
        if (hasDept1) {
          this.queryParams.rdcType = 'DEPT1'
        } else if (hasDept2) {
          this.queryParams.rdcType = 'DEPT2'
        } else {
          this.queryParams.rdcType = 'NoList'
        }
      }
    },
    handleDetail(row) {
      this.$refs.constructionDetailRef.init(row)
    },
    previewDisabled(data) {
      let noPreview = true
      for (let i = 0; i < data.scores.length; i++) {
        if (data.scores[i].scoreInput) {
          noPreview = false
        }
      }
      return noPreview
    },
    /**
     * 处理报表预览点击
     * @param row
     */
    handleReportPreview(row) {
      this.$refs[this.processType + 'ReportPreviewRef'].init(row)
    },
    submitSuccess() {
      this.getList()
    },
    /** 查询专业类别列表 */
    getSpecialList() {
      this.getDicts('cq_process_type').then(async response => {
        this.specialTypes = response.data
        // const path = this.$route.path
        // this.specialTypeName = path.includes('ConstructionCourse') ? '土建' : '精装'
        // const constructionSpecialType = this.specialTypes.find(item => item.dictLabel.includes(this.specialTypeName))
        // this.processType = constructionSpecialType && constructionSpecialType.dictValue
        // this.queryParams.processType = this.processType
        this.getRandoTypePermission()
        await this.getChildrenCfg()
        this.getList()
      })
        .catch(() => (this.loading = false))
    },
    // 显示评分列表
    leakage(scoreItem, row) {
      console.log(scoreItem)
      console.log(row)
      // const { processType } = this
      const { isLockout } = row
      // 锁定状态不可点击
      if (isLockout) return this.$message.info('已被锁定，无法操作')

      // const title = scoreItem.chkitemName
      // const params = { title, scoreItem.chkitemName }
      // if (ytType) {
      //   params.title = `${params.title}-${ytType.label}`
      //   params.productType = ytType.value
      // }
      this.$refs.antiseepRef.show = true
      this.$refs.antiseepRef.init(row, scoreItem)
    },
    async getChildrenCfg() {
      const { versionCode, chkitemId } = this.cfgInfo
      if (!versionCode || !chkitemId) return

      const opt = { versionCode, parentId: chkitemId, isEnable: 1 }
      this.loading = true
      const res = await listChkitem(opt).catch(() => false)
      this.loading = false
      if (res === false) return

      const data = res.data || []
      await this.getEnumDicts(data)
      data.map(i => {
        i.chkitemCfgId = i.cfgId
      })
      // 排序
      data.sort((a, b) => {
        if (a.seq !== b.seq) return b.seq - a.seq
        return (a.chkitemCode || '').localeCompare(b.chkitemCode || '')
      })
      this.scoreTypeList = data
      this.cfgInfo.children = data
    },
    async getEnumDicts(list) {
      // 获取枚举字典
      const enumList = list.filter(i => i.dataType === DATA_TYPE.ENUM)
      if (!enumList.length) return list

      const arr = enumList.map(i => i.scoreType)
      // 去重
      const dictNames = arr.filter((a, b) => arr.indexOf(a) === b)

      this.loading = true
      const res = await Promise.all(
        dictNames.map(dictName =>
          this.getDicts(dictName)
            .then(res => ({ [dictName]: (res.data || []).map(i => ({ label: i.dictLabel, value: i.dictValue, raw: i })) }))
            .catch(() => ({}))
        )
      ).catch(() => false)
      this.loading = false
      if (res === false) return list

      const data = res.reduce((o, i) => !void (o = { ...o, ...i }) && o, {})
      enumList.map(i => (i.enumDicts = data[i.scoreType] || []))
      return list
    },
    /** 查询土建列表 */
    async getList() {
      const { showBtns } = this
      const opt = this.getQuery()
      if (!opt) return

      this.loading = true
      const res = await pageScorePrjchk(opt).catch(() => false)
      this.loading = false
      if (res === false) return

      const data = res.rows || []
      const deptName = i => [i.deptName1, i.deptName2, i.deptName3].filter(i => i).join(' - ')
      data.map(i => {
        i.showDeptName = deptName(i)
        i.isEnableLoading = false
        i.isEditEnable = i.isLockout ? showBtns.enable : showBtns.disable
        i.showBtns = showBtns
        i.isRecheck = false // 是否 需要复查
        i.exportLoading = false // 任务下载状态
        i.forceRemoveLoading = false

        for (let j = 0; j < this.scoreTypeList.length; j++) {
          const scoreClassVal = this.$options.filters['scoreClass'](i[this.scoreTypeList[j].key + 'Level'], this.scoreTypeList[j].key)
          if (scoreClassVal === 'red' && i.chkStep === 'NEEDRECHK' || i.chkStep === 'NEEDDOUCHK') {
            i.isRecheck = true
          }
        }

        let scores = i.scores
        scores.sort((a, b) => {
          return (a.chkitemCode || '').localeCompare(b.chkitemCode || '')
        })
        scores.forEach(scoreItem => {
          scoreItem.children = []
        })
        const GCBS = scores.filter(item => item.productType === 'HIGH' || item.productType === 'VILLA') // 高层别墅
        GCBS.sort((a, b) => {
          return a.productType.localeCompare(b.productType)
        })
        scores = scores.filter(item => item.productType !== 'HIGH' && item.productType !== 'VILLA')
        const list = scores.filter(scoreItem => scoreItem.parentId === this.cfgInfo.chkitemId)
        list.forEach(scoreItem => {
          for (let i = 0; i < scores.length; i++) {
            if (scoreItem.chkitemId === scores[i].parentId) {
              for (let j = 0; j < GCBS.length; j++) { // 第三级  高层与别墅
                if (GCBS[j].chkitemId === scores[i].chkitemId) {
                  scores[i].children.push({...GCBS[j]})
                }
              }
              scoreItem.children.push({...scores[i]})
            }
          }
        })
        i.scores = list
      })

      if (data.length > 0) {
        this.scoreTypeList = JSON.parse(JSON.stringify(data[0].scores))
        // console.log('-----------------', this.scoreTypeList)
      }

      this.constructionList = data
      this.total = res.total || 0
    },
    getQuery() {
      const { dateRange } = this
      const opt = { ...this.queryParams }
      if (Array.isArray(dateRange) && dateRange.length === 2) {
        opt.startTime = dateRange[0]
        opt.endTime = dateRange[1]
      } else {
        opt.startTime = ''
        opt.endTime = ''
      }
      opt.chkitemCode = this.$route.query.chkitemCode
      opt.versionCode = this.$route.query.versionCode
      return opt
    },
    /**
       * 查询部门与项目下拉树结构
       */
    getDeptTree() {
      treeselect({}).then((response) => {
        this.deptOptions = response.data
      })
    },
    getProjectList(node) {
      this.queryParams.projectName = ''
    },
    /** 转换检索部门数据结构 */
    normalizerDept(node) {
      if (node.children && !node.children.length) {
        delete node.children
      }
      return {
        id: node.fid,
        label: node.label,
        children: node.children
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.roleId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    // 复查
    handleRecheck(row) {
      const rowData = JSON.parse(JSON.stringify(row))
      this.$refs.addUpdateRef.handleRecheck(rowData)
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.addUpdateRef.handleAdd()
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs.addUpdateRef.handleUpdate(row)
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$confirm(`是否确认删除当前${this.specialTypeName}的数据项?`, '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return cqEvalPrjchkRemove({ prjchkId: row.prjchkId, checkDate: row.checkDate })
      }).then(() => {
        this.getList()
        this.msgSuccess('删除成功')
      }).catch(function() {
      })
    },
    // 强制删除
    async handleForceRemove(item) {
      const res1 = await this.$confirm(`确认强制删除当前${this.specialTypeName}的数据项?`, '警告', { type: 'warning' }).catch(() => false)
      if (res1 !== 'confirm') return

      const opt = { prjchkId: item.prjchkId, checkDate: item.checkDate }
      item.forceRemoveLoading = true
      const res = await cqEvalPrjchkForceRemove(opt).catch(() => false)
      item.forceRemoveLoading = false
      if (res === false) return

      this.msgSuccess('删除成功')
      this.getList()
    },
    async handleExport() {
      if (!this.constructionList.length) return this.msgInfo('暂无数据')
      const opt = this.getQuery()
      if (!opt) return
      // 不传分页参数
      delete opt.pageNum
      delete opt.pageSize

      const filename = `${this.specialTypeName}检查表`
      const res1 = await this.$confirm(`确定导出${filename}?`, '警告', { type: 'warning' }).catch(() => false)
      if (res1 !== 'confirm') return

      this.exportLoading = true
      const res = await exportReportPrjchk(opt).catch(() => false)
      this.exportLoading = false
      if (res === false) return

      const elink = document.createElement('a')
      elink.download = `${filename}_${new Date().Format('yyyyMMdd')}.xlsx`
      elink.style.display = 'none'
      elink.href = URL.createObjectURL(new Blob([res]))
      elink.click()
    },
    async handleTaskExport(row) {
      const filename = `${row.projectName} - ${this.specialTypeName}（${this.dict.label.cq_random_type[row.rdcType]}）检查整改联系单_${new Date().Format('yyyyMMdd')}.docx`
      const res1 = await this.$confirm(`确定导出《${filename}》?`, '警告', { type: 'warning' }).catch(() => false)
      if (res1 !== 'confirm') return
      row.exportLoading = true
      const res = await getProcessWordRecord({taskId: row.prjchkId}).catch(() => false)
      row.exportLoading = false
      if (res === false) return

      const elink = document.createElement('a')
      elink.download = `${filename}`
      elink.style.display = 'none'
      elink.href = URL.createObjectURL(new Blob([res]))
      elink.click()
    },
    async toggleIsEnable(item) {
      if (item.isEnableLoading) return
      const isLockout = item.isLockout ? 0 : 1
      const name = isLockout === 1 ? '锁定' : '解锁'
      const res1 = await this.$confirm(`确认${name}?`, '警告', { type: 'warning' }).catch(() => false)
      if (res1 !== 'confirm') return

      const opt = { prjchkId: item.prjchkId, isLockout }
      const submitApi = isLockout ? disableTaskPrjchk : enableTaskPrjchk
      item.isEnableLoading = true
      const res = await submitApi(opt).catch(() => false)
      item.isEnableLoading = false
      if (res === false) return

      this.$message.success(`已${name}`)
      this.getList()
    }
  }
}
</script>

<style lang="scss" scoped>
  $borderColor: #E4E7ED;
  .tree-select-custom {
    width: 300px;
    /deep/ {
      .vue-treeselect__control {
        height: 28px;
        font-size: 12px;
      }
      .vue-treeselect__placeholder,
      .vue-treeselect__single-value {
        line-height: 26px;
      }
      .vue-treeselect__input-container,
      .vue-treeselect__input {
        height: 26px;
      }
    }
  }
.material-tab {
  .material-item {
    padding: 6px 10px;
    margin: 0 10px;
  }
}
.material-item {
  display: inline-block;
  text-align: center;
  padding: 2px 10px;
  color: #909399;
  border: 1px currentColor dashed;
  border-radius: 4px;
  vertical-align: top;
}
  .item-cursor {
    cursor: pointer;
    &:hover {
      /*color: #409EFF;*/
    }
  }
.item-special {
  .material-item-type {
    display: flex;
    .type-line  {
      border-right: 1px currentColor dashed;
      margin: -6px 10px;
    }
    .gc-bs {
      cursor: pointer;
    }
    .label-value {
      text-align: left;
      span:nth-child(1) {
        margin-right: 10px;
      }
      &:hover {
        color: #409EFF;
      }
    }
  }
}
.EXCELLENT,
.green {
  color: #67c23a;
}
.VALID,
.blue {
  color: #409eff;
}
.UNVALID,
.red {
  color: #f56c6c;
}
</style>
